package com.zhihuichongcheng.application.ui.task.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.zhihuichongcheng.application.R;
import com.zhihuichongcheng.application.base.BaseActivity;
import com.zhihuichongcheng.application.bean.mine.UserBean;
import com.zhihuichongcheng.application.ui.task.adapter.holder.UserHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * UserAdapter Created by LK on 2017/2/9.
 */
public class UserAdapter extends RecyclerView.Adapter<UserHolder> {
    private List<UserBean> dataList = new ArrayList<>();
    private BaseActivity activity;
    private OnUserClickListener onUserClickListener;

    public UserAdapter(BaseActivity activity) {
        this.activity = activity;
    }

    public void reSetData(List<UserBean> taskBeanList) {
        clear();
        setData(taskBeanList);
    }

    public void clear() {
        this.dataList.clear();
    }

    public void setData(List<UserBean> data) {
        this.dataList.addAll(data);
    }

    @Override
    public UserHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_user, parent, false);
        return new UserHolder(itemView, activity);
    }

    @Override
    public void onBindViewHolder(UserHolder holder, final int position) {
        holder.setData(dataList.get(position));
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != onUserClickListener) {
                    onUserClickListener.onUserClick(dataList.get(position));
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }


    public void setOnUserClickListener(OnUserClickListener onUserClickListener) {
        this.onUserClickListener = onUserClickListener;
    }

    public interface OnUserClickListener {
        void onUserClick(UserBean userBean);
    }
}
